home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpcsrc.lha
/
fpc
/
compiler
/
ptconst.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-09-24
|
21KB
|
527 lines
{
$Id: ptconst.pas,v 1.1.1.1.2.1 1998/07/29 12:31:41 carl Exp $
Copyright (c) 1998 by Florian Klaempfl
Reads typed constants
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit ptconst;
interface
uses symtable;
{ this procedure reads typed constants }
procedure readtypedconst(def : pdef);
implementation
uses
cobjects,globals,scanner,aasm,tree,pass_1,
hcodegen,types,verbose
{ parser specific stuff }
,pbase,pexpr
{ processor specific stuff }
{$ifdef i386}
,i386
{$endif}
{$ifdef m68k}
,m68k
{$endif}
;
{ this procedure reads typed constants }
procedure readtypedconst(def : pdef);
var
j: integer;
p : ptree;
i,l : longint;
ll : plabel;
s : string;
ca : pchar;
aktpos : longint;
pd : pprocdef;
hp1,hp2 : pdefcoll;
value : bestreal;
{problem with fldt !!
anyway .valued is not extended !!
value : double; }
procedure check_range;
begin
if ((p^.value>porddef(def)^.bis) or
(p^.value<porddef(def)^.von)) then
Message(parser_e_range_check_error);
end;
{$R-} {Range check creates problem with init_8bit(-1) !!}
begin
j:=0;
case def^.deftype of
orddef:
begin
p:=expr;
do_firstpass(p);
case porddef(def)^.typ of
s8bit,
u8bit : begin
if not is_constintnode(p) then
{ is't an int expected }
Message(cg_e_illegal_expression)
else
begin
datasegment^.concat(new(pai_const,init_8bit(p^.value)));
check_range;
end;
end;
s32bit : begin
if not is_constintnode(p) then
Message(cg_e_illegal_expression)
else
begin
datasegment^.concat(new(pai_const,init_32bit(p^.value)));
check_range;
end;
end;
u32bit : begin
if not is_constintnode(p) then
Message(cg_e_illegal_expression)
else
datasegment^.concat(new(pai_const,init_32bit(p^.value)));
end;
bool8bit : begin
if not is_constboolnode(p) then
Message(cg_e_illegal_expression);
datasegment^.concat(new(pai_const,init_8bit(p^.value)));
end;
uchar : begin
if not is_constcharnode(p) then
Message(cg_e_illegal_expression);
datasegment^.concat(new(pai_const,init_8bit(p^.value)));
end;
u16bit,
s16bit : begin
if not is_constintnode(p) then
Message(cg_e_illegal_expression);
datasegment^.concat(new(pai_const,init_16bit(p^.value)));
check_range;
end;
end;
disposetree(p);
end;
floatdef:
begin
p:=expr;
do_firstpass(p);
if is_constrealnode(p) then
value:=p^.valued
else if is_constintnode(p) then
value:=p^.value
else
Message(cg_e_illegal_expression);
case pfloatdef(def)^.typ of
s64real : datasegment^.concat(new(pai_double,init(value)));
s32real : datasegment^.concat(new(pai_single,init(value)));
s80real : datasegment^.concat(new(pai_extended,init(value)));
s64bit : datasegment^.concat(new(pai_comp,init(value)));
f32bit : datasegment^.concat(new(pai_const,init_32bit(trunc(value*65536))));
else internalerror(18);
end;
disposetree(p);
end;
pointerdef:
begin
p:=expr;
do_firstpass(p);
{ nil pointer ? }
if p^.treetype=niln then
datasegment^.concat(new(pai_const,init_32bit(0)))
{ maybe pchar ? }
else if (ppointerdef(def)^.definition^.deftype=orddef) and
(porddef(ppointerdef(def)^.definition)^.typ=uchar) then
begin
getlabel(ll);
{ insert string at the begin }
if p^.treetype=stringconstn then
generate_ascii_insert((p^.values^)+#0)
else if is_constcharnode(p) then
datasegment^.insert(new(pai_string,init(char(byte(p^.value))+#0)))
else Message(cg_e_illegal_expression);
datasegment^.insert(new(pai_label,init(ll)));
{ insert label }
datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(ll)))));
end
else if p^.treetype=addrn then
begin
if (is_equal(ppointerdef(p^.resulttype)^.definition,ppointerdef(def)^.definition) or
(is_equal(ppointerdef(p^.resulttype)^.definition,voiddef)) or
(is_equal(ppointerdef(def)^.definition,voiddef))) and
(p^.left^.treetype = loadn) then
begin
datasegment^.concat(new(pai_const,init_symbol(
strpnew(p^.left^.symtableentry^.mangledname))));
if p^.left^.symtableentry^.owner^.symtabletype=unitsymtable then
concat_external(p^.left^.symtableentry^.mangledname,EXT_NEAR);
end
else
Message(cg_e_illegal_expression);
end
else
{ allow typeof(Object type)}
if (p^.treetype=inlinen) and
(p^.inlinenumber=in_typeof_x) then
if (p^.left^.treetype=typen) then
begin
datasegment^.concat(new(pai_const,init_symbol(
strpnew(pobjectdef(p^.left^.resulttype)^.vmt_mangledname))));
if pobjectdef(p^.left^.resulttype)^.owner^.symtabletype=unitsymtable then
concat_external(pobjectdef(p^.left^.resulttype)^.vmt_mangledname,EXT_NEAR);
end
else
begin
Message(cg_e_illegal_expression);
end
else
Message(cg_e_illegal_expression);
disposetree(p);